#version 450
#extension GL_ARB_separate_shader_objects : enable

layout(constant_id = 0) const uint numBaseTextures = 1;

layout(set = 0, binding = 0) uniform sampler2D baseTextureSampler[numBaseTextures];

layout(set = 1, binding = 0) uniform TileSettings 
{
    ivec3 tileIndex;
} tileSettings;

layout(set = 2, binding = 0) uniform MyColor
{
    float colorID;
    float alpha;
} mycolor;

layout (location = 0) in vec4 inUV;
layout (location = 1) in float inLodBias;
layout (location = 2) in vec3 inNormal;
layout (location = 3) in vec3 inViewVec;
layout (location = 4) in vec3 inLightVec;
layout (location = 5) in vec3 inIJK;


layout(location = 0) out vec4 outColor;

void main() {
    //outColor = texture(baseTextureSampler[tileSettings.tileIndex], fragTexCoord);
    //outColor = vec4(mycolor.color,0,0,1); 
    
    float texcoords[4] = { inUV.x, inUV.y, inUV.z, inUV.w };
    int showID = int(mycolor.colorID + 0.5);
    float sampleTexcoord = texcoords[showID];
    vec4 color = texture(baseTextureSampler[0], vec2(sampleTexcoord, 0.5));
	vec3 N = normalize(inNormal);
	vec3 L = normalize(inLightVec);
	vec3 V = normalize(inViewVec);
	vec3 R = reflect(-L, N);
	vec3 diffuse = max(dot(N, L), 0.0) * vec3(3.0);
	float specular = pow(max(dot(R, V), 0.0), 32.0) * color.a;
	outColor = vec4(diffuse * color.rgb + specular, 1.0);
    outColor = color;
    int ix = int(inIJK.x + 0.5);
    int iy = int(inIJK.y + 0.5);
    int iz = int(inIJK.z + 0.5);
    
    if (ix == tileSettings.tileIndex.x && iy == tileSettings.tileIndex.y && iz == tileSettings.tileIndex.z)
    {
     // outColor = 1 - outColor;
       outColor = vec4(1, 0, 1, 1);
    }
    //outColor = vec4(mycolor.alpha, 0, 0, 1);
    outColor.a = mycolor.alpha;
    //mycolor.alpha;
    //outColor = vec4(tileSettings.tileIndex.x, tileSettings.tileIndex.y, tileSettings.tileIndex.z,1);
    //color;
    //vec4(inUV.y, 0, 0, 1);
}
